var e = require;
var t = module;
var o = cc.Enum({None: 0, Horizontal: 1, Vertical: 2});
cc.Class({
    extends: cc.Component,
    editor: {menu: "快速工具组件/ToolListView"},
    properties: {
        width: 500,
        height: 400,
        listViewType: {
            type: cc.Enum(o),
            default: o.None,
            notify: function (e) {
                this.refreshView(e);
            }
        }
    },
    refreshView: function () {
        if (
            (null == this.node.getComponent(cc.ScrollView) && this.node.addComponent(cc.ScrollView),
            null == this.node.getChildByName("view"))
        ) {
            var e = new cc.Node("view");
            (e.parent = this.node), e.addComponent(cc.Mask), e.addComponent(cc.Widget);
            var t = e.getComponent(cc.Widget);
            (t.target = this.node),
                (t.isAlignBottom = !0),
                (t.bottom = 0),
                (t.isAlignTop = !0),
                (t.top = 0),
                (t.isAlignLeft = !0),
                (t.left = 0),
                (t.isAlignRight = !0),
                (t.right = 0);
        }
        var n = this.node.getChildByName("view");
        if (null == n.getChildByName("content")) {
            var i = new cc.Node("content");
            i.parent = n;
            var a = i.addComponent(cc.Widget);
            this.listViewType == o.Vertical
                ? ((i.anchorY = 1),
                  (a.isAlignTop = !0),
                  (a.top = 0),
                  (a.isAlignLeft = !0),
                  (a.left = 0),
                  (a.isAlignRight = !0),
                  (a.right = 0),
                  (a.target = n))
                : ((i.anchorX = 0),
                  (a.isAlignTop = !0),
                  (a.top = 0),
                  (a.isAlignLeft = !0),
                  (a.left = 0),
                  (a.isAlignBottom = !0),
                  (a.bottom = 0),
                  (a.target = n));
        }
        0 == this.node.width && (this.node.width = this.width),
            0 == this.node.height && (this.node.height = this.height),
            n.getChildByName("content").getChildByName("item") &&
                n.getChildByName("content").getChildByName("item").destroy();
        var r = new cc.Node("item");
        (r.parent = n.getChildByName("content")),
            this.listViewType == o.Vertical
                ? ((r.width = this.node.width), (r.height = 100), (r.y = -50))
                : ((r.height = this.node.height), (r.width = 100), (r.x = 50)),
            this.node.getComponent("ListView_Horizontal") && this.node.removeComponent("ListView_Horizontal"),
            this.node.getComponent("ListView_Vertical") && this.node.removeComponent("ListView_Vertical"),
            this.node.getComponent("ListView") && this.node.removeComponent("ListView"),
            this.node.addComponent("ListView"),
            (this.node.getComponent(cc.ScrollView).content = n.getChildByName("content")),
            (this.node.getComponent(cc.ScrollView).brake = 0.3),
            this.listViewType == o.Vertical
                ? (this.node.addComponent("ListView_Vertical"),
                  (this.node.getComponent(cc.ScrollView).vertical = !0),
                  (this.node.getComponent(cc.ScrollView).horizontal = !1))
                : (this.node.addComponent("ListView_Horizontal"),
                  (this.node.getComponent(cc.ScrollView).horizontal = !0),
                  (this.node.getComponent(cc.ScrollView).vertical = !1)),
            "New Node" == this.node.name && (this.node.name = "listView"),
            this.listViewType != o.None && this.node.removeComponent("ToolListView");
    }
});
